#include <iostream>

using namespace std;

struct Node
{
	int data;
	Node* next;

	Node()
	{
		data = 0;
		next = nullptr;
	}

	Node(int x, Node* p = nullptr)
	{
		data = x;
		next = p;
	}
};

Node* head = new Node;
Node* tail = head;

bool empty(void)
{
    return head == tail;
}

void push(int x)
{
    Node* tmp = new Node(x);
    tail->next = tmp;
    tail = tmp;
}

int pop(void)
{
    if (empty())
        return ~(1<<31);
    Node* first = head->next;
    int data = first->data;
    if (first->next == nullptr)
        tail = head;
    head->next = first->next;
    delete first;
    return data;
}

int query()
{
    if (empty())
        return ~(1<<31);
    return head->next->data;
}
